package client.global.commlib.dialog

import android.net.Uri
import androidx.fragment.app.FragmentActivity
import client.global.commlib.R
import client.global.commlib.databinding.DialogCameraorselectBinding
import client.global.commlib.utils.PhotoUtils
import com.tzstore.oo.dialog.BottomBindingDialog

class CameraOrSelectDialog(context: FragmentActivity) :
    BottomBindingDialog<DialogCameraorselectBinding>(context) {
    val activity: FragmentActivity

    init {
        activity = context
    }

    override fun getV(): Int {
        return R.layout.dialog_cameraorselect
    }

    override fun postBinding() {
        binding.event = this
    }

    var suc: ((uri: Uri?) -> Unit)? = null

    fun camera() {
        cancel()
        PhotoUtils.camera(activity.supportFragmentManager) { uri, success, msg ->
            //uri返回的图片 success是否成功 msg错误信息
            if (success) {
                suc?.invoke(uri)
            }
        }
    }

    fun select() {
        cancel()
        PhotoUtils.select(activity.supportFragmentManager) { uri, success, msg ->
            if (success)
                suc?.invoke(uri)
        }
    }
}